/*
 * @Author: liangliang
 * @Date: 2023-07-25 16:14:05
 * @LastEditors: liangliang
 * @LastEditTime: 2023-07-25 16:15:15
 * @Description:
 */
import { useLayoutEffect, useRef } from 'react';
import { Location, useLocation } from 'react-router-dom';
import { ROUTER_BASENAME } from '@/config/router';
type PathnameChangeCallback = (location: Location & { fullPathname: string; }) => void;
export const usePathnameChange = (pathnameChangeCallback: PathnameChangeCallback) => {
    const pathnameChangeCallbackRef = useRef(pathnameChangeCallback);
    pathnameChangeCallbackRef.current = pathnameChangeCallback;
    const location = useLocation();
    const {
        pathname,
    } = location;
    useLayoutEffect(() => {
        pathnameChangeCallbackRef.current({ fullPathname: `${ROUTER_BASENAME}${pathname}`, ...location });
    // eslint-disable-next-line react-hooks/exhaustive-deps
    }, [pathname]);
};